# sdl3_image cmake project-config input for CMakeLists.txt script

include(FeatureSummary)
set_package_properties(SDL3_image PROPERTIES
    URL "https://www.libsdl.org/projects/SDL_image/"
    DESCRIPTION "SDL_image is an image file loading library"
)

set(SDL3_image_FOUND ON)

set(SDL3IMAGE_AVIF  @SDL3IMAGE_AVIF@)
set(SDL3IMAGE_BMP   @SDL3IMAGE_BMP@)
set(SDL3IMAGE_GIF   @SDL3IMAGE_GIF@)
set(SDL3IMAGE_JPG   @SDL3IMAGE_JPG@)
set(SDL3IMAGE_JXL   @SDL3IMAGE_JXL@)
set(SDL3IMAGE_LBM   @SDL3IMAGE_LBM@)
set(SDL3IMAGE_PCX   @SDL3IMAGE_PCX@)
set(SDL3IMAGE_PNG   @SDL3IMAGE_PNG@)
set(SDL3IMAGE_PNM   @SDL3IMAGE_PNM@)
set(SDL3IMAGE_QOI   @SDL3IMAGE_QOI@)
set(SDL3IMAGE_SVG   @SDL3IMAGE_SVG@)
set(SDL3IMAGE_TGA   @SDL3IMAGE_TGA@)
set(SDL3IMAGE_TIF   @SDL3IMAGE_TIF@)
set(SDL3IMAGE_XCF   @SDL3IMAGE_XCF@)
set(SDL3IMAGE_XPM   @SDL3IMAGE_XPM@)
set(SDL3IMAGE_XV    @SDL3IMAGE_XV@)
set(SDL3IMAGE_WEBP  @SDL3IMAGE_WEBP@)

set(SDL3IMAGE_JPG_SAVE @SDL3IMAGE_JPG_SAVE@)
set(SDL3IMAGE_PNG_SAVE @SDL3IMAGE_PNG_SAVE@)

set(SDL3IMAGE_VENDORED  @SDL3IMAGE_VENDORED@)

set(SDL3IMAGE_BACKEND_IMAGEIO   @SDL3IMAGE_BACKEND_IMAGEIO@)
set(SDL3IMAGE_BACKEND_STB       @SDL3IMAGE_BACKEND_STB@)
set(SDL3IMAGE_BACKEND_WIC       @SDL3IMAGE_BACKEND_WIC@)

set(SDL3IMAGE_SDL3_REQUIRED_VERSION  @SDL_REQUIRED_VERSION@)

if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_image-shared-targets.cmake")
    include("${CMAKE_CURRENT_LIST_DIR}/SDL3_image-shared-targets.cmake")
endif()

if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_image-static-targets.cmake")

    if(SDL3IMAGE_VENDORED)
        if(SDL3IMAGE_JXL)
            include(CheckLanguage)
            check_language(CXX)
            if(NOT CMAKE_CXX_COMPILER AND NOT _sdl3image_nowarning)
                message(WARNING "CXX language not enabled. Linking to SDL3_image::SDL3_image-static might fail.")
            endif()
        endif()
    else()
        set(_sdl_cmake_module_path "${CMAKE_MODULE_PATH}")
        list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

        include(CMakeFindDependencyMacro)

        if(SDL3IMAGE_AVIF AND NOT TARGET avif)
            find_dependency(libavif @LIBAVIF_MINIMUM_VERSION@)
        endif()

        if(SDL3IMAGE_JPG AND NOT TARGET JPEG::JPEG)
            find_dependency(JPEG)
        endif()

        if(SDL3IMAGE_JXL AND NOT TARGET libjxl::libjxl)
            list(APPEND libjxl_ROOT "${CMAKE_CURRENT_LIST_DIR}")
            find_dependency(libjxl)
        endif()

        if(SDL3IMAGE_PNG AND NOT TARGET PNG::PNG)
            find_dependency(PNG)
        endif()

        if(SDL3IMAGE_TIF AND NOT TARGET TIFF::TIFF)
            find_dependency(TIFF)
        endif()

        if(SDL3IMAGE_WEBP AND NOT TARGET WebP::webp)
            list(APPEND webp_ROOT "${CMAKE_CURRENT_LIST_DIR}")
            find_dependency(webp)
        endif()

        set(CMAKE_MODULE_PATH "${_sdl_cmake_module_path}")
        unset(_sdl_cmake_module_path)

    endif()

    include("${CMAKE_CURRENT_LIST_DIR}/SDL3_image-static-targets.cmake")
endif()

function(_sdl_create_target_alias_compat NEW_TARGET TARGET)
    if(CMAKE_VERSION VERSION_LESS "3.18")
        # Aliasing local targets is not supported on CMake < 3.18, so make it global.
        add_library(${NEW_TARGET} INTERFACE IMPORTED)
        set_target_properties(${NEW_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET}")
    else()
        add_library(${NEW_TARGET} ALIAS ${TARGET})
    endif()
endfunction()

# Make sure SDL3_image::SDL3_image always exists
if(NOT TARGET SDL3_image::SDL3_image)
    if(TARGET SDL3_image::SDL3_image-shared)
        _sdl_create_target_alias_compat(SDL3_image::SDL3_image SDL3_image::SDL3_image-shared)
    else()
        _sdl_create_target_alias_compat(SDL3_image::SDL3_image SDL3_image::SDL3_image-static)
    endif()
endif()
